package com.dabaozhan.modules.wx_app.service.impl;

import com.dabaozhan.common.entity.Query;
import com.dabaozhan.common.utils.OmsPage;
import com.dabaozhan.common.utils.Utils;
import com.dabaozhan.modules.wx_app.dao.SiteOrderMapper;
import com.dabaozhan.modules.wx_app.entity.SiteOrderEntity;
import com.dabaozhan.modules.wx_app.service.SiteOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author houzhong
 * @date 2019-01-07 12:32
 */
@Service("siteOrderService")
public class SiteOrderServiceImpl implements SiteOrderService {

    @Autowired
    private SiteOrderMapper siteOrderMapper;

    @Override
    public int saveSiteOrder(SiteOrderEntity v) {
        if (v.getId() == null) {
            v.setId(Utils.id().toString());
        }
        return siteOrderMapper.save(v);
    }

    @Override
    public int updateSiteOrder(SiteOrderEntity v) {
        return siteOrderMapper.update(v);
    }

    @Override
    public SiteOrderEntity findById(String id) {
        return siteOrderMapper.getObjectById(id);
    }

    @Override
    public int findBySiteOrderCount(Map<String, Object> params) {
        Query query = new Query(params);
        return siteOrderMapper.findBySiteOrderCount(query);
    }

    @Override
    public OmsPage<SiteOrderEntity> findBySiteOrder(Map<String, Object> params) {
        Query query = new Query(params);
        OmsPage<SiteOrderEntity> pages = new OmsPage<SiteOrderEntity>();
        pages.setTotal(siteOrderMapper.findBySiteOrderCount(query));
        List<SiteOrderEntity> list = siteOrderMapper.findBySiteOrder(query);
        pages.setResult(list);
        return pages;
    }

	@Override
	public SiteOrderEntity getSiteOrderByOrderNumber(String orderNumber) {
		return siteOrderMapper.getSiteOrderByOrderNumber(orderNumber);
	}

	@Override
	public List<SiteOrderEntity> getSiteOrderBySupplierUserIdAndPackerId(String supplierUserId,String packerId) {
		return siteOrderMapper.getSiteOrderBySupplierUserIdAndPackerId(supplierUserId,packerId);
	}

    @Override
    public List<SiteOrderEntity> getSiteOrderCategoryId(String userId, String categoryId, String parentId) {
        return siteOrderMapper.getSiteOrderCategoryId(userId, categoryId, parentId);
    }
}
